// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Fluent;
using Elastic.Clients.Elasticsearch.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.MachineLearning;

public sealed partial class DataframeAnalysisOutlierDetection
{
	/// <summary>
	/// <para>
	/// Specifies whether the feature influence calculation is enabled.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("compute_feature_influence")]
	public bool? ComputeFeatureInfluence { get; set; }

	/// <summary>
	/// <para>
	/// The minimum outlier score that a document needs to have in order to calculate its feature influence score. Value range: 0-1.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("feature_influence_threshold")]
	public double? FeatureInfluenceThreshold { get; set; }

	/// <summary>
	/// <para>
	/// The method that outlier detection uses. Available methods are <c>lof</c>, <c>ldof</c>, <c>distance_kth_nn</c>, <c>distance_knn</c>, and <c>ensemble</c>. The default value is ensemble, which means that outlier detection uses an ensemble of different methods and normalises and combines their individual outlier scores to obtain the overall outlier score.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("method")]
	public string? Method { get; set; }

	/// <summary>
	/// <para>
	/// Defines the value for how many nearest neighbors each method of outlier detection uses to calculate its outlier score. When the value is not set, different values are used for different ensemble members. This default behavior helps improve the diversity in the ensemble; only override it if you are confident that the value you choose is appropriate for the data set.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("n_neighbors")]
	public int? NNeighbors { get; set; }

	/// <summary>
	/// <para>
	/// The proportion of the data set that is assumed to be outlying prior to outlier detection. For example, 0.05 means it is assumed that 5% of values are real outliers and 95% are inliers.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("outlier_fraction")]
	public double? OutlierFraction { get; set; }

	/// <summary>
	/// <para>
	/// If true, the following operation is performed on the columns before computing outlier scores: <c>(x_i - mean(x_i)) / sd(x_i)</c>.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("standardization_enabled")]
	public bool? StandardizationEnabled { get; set; }

	public static implicit operator Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalysis(DataframeAnalysisOutlierDetection dataframeAnalysisOutlierDetection) => Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalysis.OutlierDetection(dataframeAnalysisOutlierDetection);
}

public sealed partial class DataframeAnalysisOutlierDetectionDescriptor : SerializableDescriptor<DataframeAnalysisOutlierDetectionDescriptor>
{
	internal DataframeAnalysisOutlierDetectionDescriptor(Action<DataframeAnalysisOutlierDetectionDescriptor> configure) => configure.Invoke(this);

	public DataframeAnalysisOutlierDetectionDescriptor() : base()
	{
	}

	private bool? ComputeFeatureInfluenceValue { get; set; }
	private double? FeatureInfluenceThresholdValue { get; set; }
	private string? MethodValue { get; set; }
	private int? NNeighborsValue { get; set; }
	private double? OutlierFractionValue { get; set; }
	private bool? StandardizationEnabledValue { get; set; }

	/// <summary>
	/// <para>
	/// Specifies whether the feature influence calculation is enabled.
	/// </para>
	/// </summary>
	public DataframeAnalysisOutlierDetectionDescriptor ComputeFeatureInfluence(bool? computeFeatureInfluence = true)
	{
		ComputeFeatureInfluenceValue = computeFeatureInfluence;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The minimum outlier score that a document needs to have in order to calculate its feature influence score. Value range: 0-1.
	/// </para>
	/// </summary>
	public DataframeAnalysisOutlierDetectionDescriptor FeatureInfluenceThreshold(double? featureInfluenceThreshold)
	{
		FeatureInfluenceThresholdValue = featureInfluenceThreshold;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The method that outlier detection uses. Available methods are <c>lof</c>, <c>ldof</c>, <c>distance_kth_nn</c>, <c>distance_knn</c>, and <c>ensemble</c>. The default value is ensemble, which means that outlier detection uses an ensemble of different methods and normalises and combines their individual outlier scores to obtain the overall outlier score.
	/// </para>
	/// </summary>
	public DataframeAnalysisOutlierDetectionDescriptor Method(string? method)
	{
		MethodValue = method;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Defines the value for how many nearest neighbors each method of outlier detection uses to calculate its outlier score. When the value is not set, different values are used for different ensemble members. This default behavior helps improve the diversity in the ensemble; only override it if you are confident that the value you choose is appropriate for the data set.
	/// </para>
	/// </summary>
	public DataframeAnalysisOutlierDetectionDescriptor NNeighbors(int? nNeighbors)
	{
		NNeighborsValue = nNeighbors;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The proportion of the data set that is assumed to be outlying prior to outlier detection. For example, 0.05 means it is assumed that 5% of values are real outliers and 95% are inliers.
	/// </para>
	/// </summary>
	public DataframeAnalysisOutlierDetectionDescriptor OutlierFraction(double? outlierFraction)
	{
		OutlierFractionValue = outlierFraction;
		return Self;
	}

	/// <summary>
	/// <para>
	/// If true, the following operation is performed on the columns before computing outlier scores: <c>(x_i - mean(x_i)) / sd(x_i)</c>.
	/// </para>
	/// </summary>
	public DataframeAnalysisOutlierDetectionDescriptor StandardizationEnabled(bool? standardizationEnabled = true)
	{
		StandardizationEnabledValue = standardizationEnabled;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (ComputeFeatureInfluenceValue.HasValue)
		{
			writer.WritePropertyName("compute_feature_influence");
			writer.WriteBooleanValue(ComputeFeatureInfluenceValue.Value);
		}

		if (FeatureInfluenceThresholdValue.HasValue)
		{
			writer.WritePropertyName("feature_influence_threshold");
			writer.WriteNumberValue(FeatureInfluenceThresholdValue.Value);
		}

		if (!string.IsNullOrEmpty(MethodValue))
		{
			writer.WritePropertyName("method");
			writer.WriteStringValue(MethodValue);
		}

		if (NNeighborsValue.HasValue)
		{
			writer.WritePropertyName("n_neighbors");
			writer.WriteNumberValue(NNeighborsValue.Value);
		}

		if (OutlierFractionValue.HasValue)
		{
			writer.WritePropertyName("outlier_fraction");
			writer.WriteNumberValue(OutlierFractionValue.Value);
		}

		if (StandardizationEnabledValue.HasValue)
		{
			writer.WritePropertyName("standardization_enabled");
			writer.WriteBooleanValue(StandardizationEnabledValue.Value);
		}

		writer.WriteEndObject();
	}
}